package com.oracle.ateam.atg.formhandler;

import java.io.IOException;

import javax.servlet.ServletException;

import atg.core.util.StringUtils;
import atg.droplet.DropletException;
import atg.droplet.GenericFormHandler;
import atg.servlet.DynamoHttpServletRequest;
import atg.servlet.DynamoHttpServletResponse;

/**
 * Sample formHander to demonstrate Dust testing
 *
 */
public class SampleFormHandler extends GenericFormHandler {

	private String username;
	private String password;

	public static final String MISSING_USERNAME = "username cannot be empty";
	public static final String MISSING_PASSWORD = "password cannot be empty";

	/**
	 * @param pRequest
	 * @param pResponse
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	public boolean handleUpdateSku(final DynamoHttpServletRequest pRequest, final DynamoHttpServletResponse pResponse)
			throws ServletException, IOException {

		if (StringUtils.isEmpty(username)) {
			addFormException(new DropletException(MISSING_USERNAME));
		}

		if (StringUtils.isEmpty(password)) {
			addFormException(new DropletException(MISSING_PASSWORD));
		}

		if (getFormError()) {
			return false;
		} else {
			return true;
		}
	}

	/**
	 * @return
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * @param username
	 */
	public void setUsername(final String username) {
		this.username = username;
	}

	/**
	 * @return
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param password
	 */
	public void setPassword(final String password) {
		this.password = password;
	}

}
